/*

analysis.do

Runs analysis for Haryana CCE Paper

Created: 01-23-2017 Jim Berry
Modified: 11-21-2018 Jim Berry

non-standard Stata:
	estout
	qqvalue

*/

*****************
* Preliminaries *
*****************

set more off

*Set paths

adopath +ado
qui do ./ado/haryana_cce_programs.do

clear
mat drop _all

capture log close
log using logs/analysis, replace

************
* PROGRAMS *
************

*Program to store confidence interval in e(upper_ci_`varname') and e(lower_ci_`varname')
capture program drop store_ci
program define store_ci
	args varname
	scalar lower_ci_`varname'=_b[`varname']-abs(invttail(e(df_r),.025)*_se[`varname'])
	estadd scalar lower_ci_`varname'
	scalar upper_ci_`varname'=_b[`varname']+abs(invttail(e(df_r),.025)*_se[`varname'])
	estadd scalar upper_ci_`varname'
	end
	

*Program to generate indices
capture program drop genindex
program define genindex
	syntax varlist, prefix(string) label(string)
	foreach var of varlist `varlist' {
		qui sum `var' if any_CCE==0
		local mean_`var'=`r(mean)'
		local sd_`var'=`r(sd)'
		gen `var'_nrm=(`var' - `mean_`var'')/`sd_`var''
		local vars_norm `vars_norm' `var'_nrm
		} 
	egen `prefix'_index=rowmean(`vars_norm')
	qui sum `prefix'_index if any_CCE==0
	replace `prefix'_index=(`prefix'_index-r(mean))/r(sd)
	label var `prefix'_index "`label'"
	drop `vars_norm'
	end

****************************************
* SUMMARY STATISTICS AND BALANCE CHECK *
****************************************


************ PRIMARY SCHOOLS ***********

use ./dta/primary_cleaned, clear

lab var female "Female"

local outcomelist_base "female age_year base_standard base_aser_read_norm base_aser_math_norm base_h_score_norm base_m_score_norm attrit"

**3 groups separate
foreach var in `outcomelist_base' {
	qui count if `var'<.
	local nobs=r(N)
	areg `var' CCE LEP CCE_LEP, cluster(super_school_id) absorb(stratum)
	qui sum `var' if e(sample)==1 & any_CCE==0 & any_LEP==0 // only sums variables from the above regression
	local control_mean=r(mean)
	local control_sd=r(sd)
	test CCE=LEP=CCE_LEP=0
	mat balance_ind=nullmat(balance_ind)\ `control_mean',_b[CCE],_b[LEP],_b[CCE_LEP],r(p),`nobs'\ `control_sd',_se[CCE],_se[LEP],_se[CCE_LEP],.,.
	}

mat balance_ind=balance_ind[.,1..4]

mat colnames balance_ind=control CCE_only LEP_only CCE_LEP 

*Without interaction
foreach var in `outcomelist_base' {
	qui count if `var'<.
	local nobs=r(N)
	areg `var' any_CCE any_LEP, cluster(super_school_id) absorb(stratum)
	qui sum `var' if e(sample)==1 & any_CCE==0 & any_LEP==0 // only sums variables from the above regression
	local control_mean=r(mean)
	local control_sd=r(sd)
	test any_CCE=any_LEP=0
	mat balance_comb=nullmat(balance_comb)\ `control_mean',_b[any_CCE],_b[any_LEP],r(p),`nobs'\ `control_sd',_se[any_CCE],_se[any_LEP],.,.
	}

mat balance_comb=balance_comb[.,2..3],balance_comb[.,5..5]
mat colnames balance_comb=any_CCE any_LEP nobs

preserve

gen outcome=""
local i 1
foreach var in `outcomelist_base' {
	replace outcome="`var'" in `i'
	local i=`i'+2
	}

keep outcome
keep if _n<`i'
	
svmat balance_ind, names(col)
svmat balance_comb, names(col)

order outcome control CCE_only LEP_only CCE_LEP any_CCE any_LEP nobs

format_col control, delimiters([])
format_col CCE_only LEP_only CCE_LEP any_CCE any_LEP, delimiters("()") stars
format_col nobs

export delimited using ./csv/balance_prim.csv, replace

format_csv using ./csv/balance_prim.csv, allquote spacers(4 6)

mat drop balance_ind balance_comb
restore

********** UPPER PRIMARY SCHOOLS *********

use ./dta/upperprimary_cleaned.dta, clear

local outcomelist_base "female age_year base_H_norm base_M_norm attrit"

foreach var in `outcomelist_base' {
	qui count if `var'<.
	local nobs=r(N)
	areg `var' any_CCE, cluster(super_school_id) absorb(stratum)
	qui sum `var' if e(sample)==1 & any_CCE==0
	mat balance=nullmat(balance)\r(mean),_b[any_CCE],`nobs'\r(sd),_se[any_CCE],.
	}

mat colnames balance=control any_CCE nobs

clear
svmat balance, names(col)

gen outcome=""
local i 1
foreach var in `outcomelist_base' {
	replace outcome="`var'" in `i'
	local i=`i'+2
	}
	
order outcome

format_col control, delimiters([])
format_col any_CCE, delimiters("()") stars
format_col nobs

export delimited using ./csv/balance_upper.csv, replace
format_csv using ./csv/balance_upper.csv, allquote


**********************************
* Data for baseline ASER graphs *
**********************************

use ./dta/primary_cleaned, clear

foreach num of num 0/4 {
	gen base_math_`num'=base_aser_math_unweighted==`num' if base_aser_math_level<.
	gen base_read_`num'=base_aser_read_unweighted==`num' if base_aser_read_level<.
	}

collapse(mean) base_math_0-base_read_4
gen i=1
reshape long base_read_ base_math_, i(i) j(level)
drop i

rename base_read_ base_read
rename base_math_ base_math
reshape long base_, i(level) j(test) string
rename base_ average

tempfile oral_means
save `oral_means'

use ./dta/primary_cleaned, clear

foreach num of num 0/4 {
	gen base_math_`num'=base_aser_math_unweighted==`num' if base_aser_math_level<.
	gen base_read_`num'=base_aser_read_unweighted==`num' if base_aser_read_level<.
	}

collapse(mean) base_math_0-base_read_4, by(base_standard)

reshape long base_read_ base_math_, i(base_standard) j(level)

rename base_read_ base_read
rename base_math_ base_math
rename base_standard standard

reshape long base_, i(standard level) j(test) string
rename base_ average


append using `oral_means'

gen all=1 if standard==.
replace all=2 if standard!=.

gsort all -test standard level
drop all

gen str label=""
replace label="Nothing" if level==0
replace label="Letters" if level==1 & test=="read"
replace label="Word" if level==2 & test=="read"
replace label="Paragraph" if level==3 & test=="read"
replace label="Story" if level==4 & test=="read"

replace label="1-Digit Number Recognition" if level==1 & test=="math"
replace label="2-Digit Number Recognition" if level==2 & test=="math"
replace label="Subtraction" if level==3 & test=="math"
replace label="Division" if level==4 & test=="math"

order test standard level label average

export delimited using ./csv/oral_means_base.csv, replace

**********************************
* Data for Endline ASER graphs *
**********************************

use ./dta/primary_cleaned, clear

gen end_aser_math_weighted_round=round(end_aser_math_weighted,1)
gen end_aser_read_weighted_round=round(end_aser_read_weighted,1)

foreach num of num 0/6 {
	gen end_math_`num'=end_aser_math_weighted_round==`num' & end_aser_math_weighted_round<.
	gen end_read_`num'=end_aser_read_weighted_round==`num' & end_aser_read_weighted_round<.
	}

collapse(mean) end_math_0-end_read_6
gen i=1
reshape long end_read_ end_math_, i(i) j(level)
drop i

rename end_read_ end_read
rename end_math_ end_math
reshape long end_, i(level) j(test) string
rename end_ average

tempfile oral_means
save `oral_means'

use ./dta/primary_cleaned, clear

gen end_aser_math_weighted_round=round(end_aser_math_weighted,1)
gen end_aser_read_weighted_round=round(end_aser_read_weighted,1)

foreach num of num 0/6 {
	gen end_math_`num'=end_aser_math_weighted_round==`num' & end_aser_math_weighted_round<.
	gen end_read_`num'=end_aser_read_weighted_round==`num' & end_aser_read_weighted_round<.
	}

collapse(mean) end_math_0-end_read_6, by(base_standard)

reshape long end_read_ end_math_, i(base_standard) j(level)

rename end_read_ end_read
rename end_math_ end_math
rename base_standard standard

reshape long end_, i(standard level) j(test) string
rename end_ average


append using `oral_means'

gen all=1 if standard==.
replace all=2 if standard!=.

gsort all -test standard level
drop all

order test standard level average

export delimited using ./csv/oral_means_end.csv, replace

**********************************
* Data for Endline written graphs *
**********************************

use dta/primary_cleaned, clear

gen writ_math_bin=round(end_m_score_weighted,1)
replace writ_math_bin=12 if writ_math_bin==13

collapse(count) count=child_id, by(writ_math_bin)
drop if writ_math_bin==.
egen total=sum(count)
gen pct=count/total

drop count total
rename writ_math_bin score
rename pct math_pct

tempfile math
save `math'

use dta/primary_cleaned, clear

gen writ_hindi_bin=round(end_h_score_weighted,1)
replace writ_hindi_bin=12 if writ_hindi_bin==13

collapse(count) count=child_id, by(writ_hindi_bin)
drop if writ_hindi_bin==.
egen total=sum(count)
gen pct=count/total

drop count total
rename writ_hindi_bin score
rename pct hindi_pct

merge 1:1 score using `math'

drop _merge
replace hindi_pct=0 if hindi_pct==.

tempfile all

save `all'

use dta/primary_cleaned, clear

gen writ_math_bin=round(end_m_score_weighted,1)
replace writ_math_bin=12 if writ_math_bin==13

collapse(count) count=child_id, by(writ_math_bin base_standard)
drop if writ_math_bin==.

egen total=sum(count), by(base_standard)
gen pct=count/total
drop if writ_math_bin==.

drop count total
rename writ_math_bin score
rename pct math_pct

tempfile math
save `math'

use dta/primary_cleaned, clear

gen writ_hindi_bin=round(end_h_score_weighted,1)
replace writ_hindi_bin=12 if writ_hindi_bin==13


collapse(count) count=child_id, by(writ_hindi_bin base_standard)
drop if writ_hindi_bin==.
egen total=sum(count), by(base_standard)
gen pct=count/total
drop if writ_hindi_bin==.
drop count total
rename writ_hindi_bin score
rename pct hindi_pct

merge 1:1 score base_standard using `math'

drop _merge

append using `all'

fillin base_standard score

drop _fillin

replace hindi_pct=0 if hindi_pct==.
replace math_pct=0 if math_pct==.

drop if base_standard==1

replace base_standard=0 if base_standard==.

sort base_standard score

outsheet using csv/writ_means_end.csv, comma replace


**********************************
* Data for Endline upper primary graphs *
**********************************

use dta/upperprimary_cleaned, clear

gen writ_math_bin=round(end_M_score,5)

collapse(count) count=child_code, by(writ_math_bin)
drop if writ_math_bin==.
egen total=sum(count)
gen pct=count/total

drop count total
rename writ_math_bin score
rename pct math_pct

tempfile math
save `math'

use dta/upperprimary_cleaned, clear

gen writ_hindi_bin=round(end_H_score,5)

collapse(count) count=child_code, by(writ_hindi_bin)
drop if writ_hindi_bin==.
egen total=sum(count)
gen pct=count/total

drop count total
rename writ_hindi_bin score
rename pct hindi_pct

merge 1:1 score using `math'

drop _merge

set obs 13
replace score=60 in 13

outsheet using csv/upper_means_end.csv, comma replace

*************
* Training  *
*************

use ./dta/teacher_roster_cleaned, clear

*First collapse creates means by school/visit over all teachers
collapse(mean) q2_4_CCE_train q2_4_CCE_notrain, by(school_id_visit school_id any_CCE)
*Second collapse creates means by school over all visits
collapse(mean) q2_4_CCE_train q2_4_CCE_notrain, by(school_id any_CCE)

estpost tabstat q2_4_CCE_train q2_4_CCE_notrain, by(any_CCE) nototal

mat means1=e(q2_4_CCE_train)\e(q2_4_CCE_notrain) // Fraction of teachers who attended CCE training in Non-CCE schools 

estpost tabstat q2_4_CCE_train, by(any_CCE) statistics(count) nototal
mat means1=means1\e(count)


use ./dta/teacher_roster_cleaned, clear

*First collapse creates means by school/visit over all teachers
collapse(mean) q2_4_CCE_train q2_4_CCE_notrain, by(school_id_visit school_id group) 
*Second collapse creates means by school over all visits
collapse(mean) q2_4_CCE_train q2_4_CCE_notrain, by(school_id group)

estpost tabstat q2_4_CCE_train q2_4_CCE_notrain, by(group) nototal

mat means2=e(q2_4_CCE_train)\e(q2_4_CCE_notrain) // Fraction of teachers who attended training 

estpost tabstat q2_4_CCE_train, by(group) statistics(count) nototal
mat means2=means2\e(count)

mat means=means1,means2

mat colnames means=total_nocce total_cce primary_nocce primary_cce upper_nocce upper_cce

clear
svmat means, names(col)

format_col total_cce total_nocce primary_nocce primary_cce upper_nocce upper_cce

gen outcome=""
replace outcome="Trained" in 1
replace outcome="Not Trained" in 2
order outcome

export delimited using ./csv/training_raw.csv, replace

format_csv using ./csv/training_raw.csv, h_space(1 2) spacers(2 4)


*************
* Materials *
*************


use ./dta/teacher_roster_cleaned, clear

collapse q2_5_CCE_man_shown q2_5_CCE_man_notshown q2_5_CCE_man_no, by(school_id any_CCE group)

estpost tabstat q2_5_CCE_man_shown q2_5_CCE_man_notshown q2_5_CCE_man_no if any_CCE==1, by(group)
mat means1=e(q2_5_CCE_man_shown)\e(q2_5_CCE_man_notshown)\e(q2_5_CCE_man_no)

use ./dta/process_cleaned, clear

collapse q7_9_4_eval_seen_uc q7_9_4_eval_noseen_uc q7_9_4_eval_no_uc ///
	q7_9_5_rpt_seen_uc q7_9_5_rpt_noseen_uc q7_9_5_rpt_no_uc, by(school_id any_CCE group)
estpost tabstat q7_9_4_eval_seen_uc q7_9_4_eval_noseen_uc q7_9_4_eval_no_uc if any_CCE==1, by(group)
mat means2=e(q7_9_4_eval_seen_uc)\e(q7_9_4_eval_noseen_uc)\e(q7_9_4_eval_no_uc)

estpost tabstat q7_9_5_rpt_seen_uc q7_9_5_rpt_noseen_uc q7_9_5_rpt_no_uc if any_CCE==1, by(group)
mat means3=e(q7_9_5_rpt_seen_uc)\e(q7_9_5_rpt_noseen_uc)\e(q7_9_5_rpt_no_uc)

*Note that all of the obs counts are the same across the panels, so just post them at the bottom
estpost tabstat q7_9_5_rpt_seen_uc if any_CCE==1, by(group) statistics(count)
mat means3=means3\e(count)

mat means=means1\means2\means3

mat colnames means=primary upper total

clear
svmat means, names(col)
gen outcome=""
local outcomes: rownames means
local i=1
foreach outcome in `outcomes' {
	replace outcome="`outcome'" in `i'
	local ++i
	}

order outcome total primary upper

format_col total primary upper

export delimited using ./csv/materials_raw.csv, replace

format_csv using ./csv/materials_raw.csv, h_space(3 3 6 6 9) n_space




***************
* TEST SCORES *
***************


local baseline_writt_read "base_h_score_norm_m0 base_h_score_norm_m"
local baseline_writt_math "base_m_score_norm_m0 base_m_score_norm_m"
local baseline_aser_read "base_aser_read_norm_m0 base_aser_read_norm_m"
local baseline_aser_math "base_aser_math_norm_m0 base_aser_math_norm_m"

local baseline_test_prim "`baseline_aser_read' `baseline_writt_read' `baseline_aser_math' `baseline_writt_math'"
local child_control_prim "female base_standard age_m0 age_m"

global controls_prim `baseline_test_prim' `child_control_prim'


local child_control_up "female age_m0 age_m"
local baseline_test_up "base_H_norm_m0 base_H_norm_m base_M_norm_m0 base_M_norm_m"


*Main results table, Primary

use ./dta/primary_cleaned, clear

areg end_aser_read_norm any_CCE any_LEP, absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store aser_read_1
		
areg end_aser_read_norm any_CCE any_LEP `baseline_test_prim', absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store aser_read_2

areg end_aser_read_norm any_CCE any_LEP `baseline_test_prim' `child_control_prim', absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store aser_read_3

areg end_h_score_norm any_CCE any_LEP, absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store writ_h_1
	
areg end_h_score_norm any_CCE any_LEP `baseline_test_prim', absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store writ_h_2

areg end_h_score_norm any_CCE any_LEP `baseline_test_prim' `child_control_prim' , absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store writ_h_3


areg end_aser_math_norm any_CCE any_LEP, absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store aser_math_1

areg end_aser_math_norm any_CCE any_LEP `baseline_test_prim', absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store aser_math_2

areg end_aser_math_norm any_CCE any_LEP `baseline_test_prim' `child_control_prim' , absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store aser_math_3

areg end_m_score_norm any_CCE any_LEP, absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store writ_m_1 

areg end_m_score_norm any_CCE any_LEP `baseline_test_prim', absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store writ_m_2

areg end_m_score_norm any_CCE any_LEP `baseline_test_prim' `child_control_prim' , absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store writ_m_3

esttab aser_read* writ_h* using ./csv/test_prim.csv, se replace ///
	keep(any_CCE any_LEP) ///
	stats(N r2 lower_ci_any_CCE upper_ci_any_CCE) ///
	nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)
	
esttab aser_math* writ_m* using ./csv/test_prim.csv, se append ///
	keep(any_CCE any_LEP) ///
	stats(N r2 lower_ci_any_CCE upper_ci_any_CCE) ///
	nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)
	
format_csv using ./csv/test_prim.csv, spacers(3)

estimates clear

*Main results table, Upper Primary

use ./dta/upperprimary_cleaned.dta, clear

areg end_H_norm CCE, absorb(stratum) vce(cluster super_school_id)
store_ci CCE
estimates store hindi_1

areg end_H_norm CCE `baseline_test_up', absorb(stratum) vce(cluster super_school_id)
store_ci CCE
estimates store hindi_2

areg end_H_norm CCE `baseline_test_up' `child_control_up' , absorb(stratum) vce(cluster super_school_id)
store_ci CCE
estimates store hindi_3

areg end_M_norm CCE, absorb(stratum) vce(cluster super_school_id)
store_ci CCE
estimates store math

areg end_M_norm CCE `baseline_test_up', absorb(stratum) vce(cluster super_school_id)
store_ci CCE
estimates store math2

areg end_M_norm CCE `baseline_test_up' `child_control_up' , absorb(stratum) vce(cluster super_school_id)
store_ci CCE
estimates store math3

esttab hindi* using ./csv/test_upper.csv, se replace keep(CCE) ///
	stats(N r2 lower_ci_CCE upper_ci_CCE) ///
	nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)

esttab math* using ./csv/test_upper.csv, se append keep(CCE) ///
	stats(N r2 lower_ci_CCE upper_ci_CCE) ///
	nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)
	
format_csv using ./csv/test_upper.csv
estimates clear


*Use IV for implementation; can use this to say that we can rule out small effects under incomplete implementation
*Primary
use ./dta/primary_cleaned, clear

ivreg end_aser_read_norm (CCE_implement_rpt=any_CCE) any_LEP `baseline_test_prim' `child_control_prim' zstratum*, cluster(super_school_id)
store_ci CCE_implement_rpt
estimates store end_aser_read_norm

ivreg end_h_score_norm (CCE_implement_rpt=any_CCE) any_LEP `baseline_test_prim' `child_control_prim' zstratum*, cluster(super_school_id)
store_ci CCE_implement_rpt
estimates store end_aser_h_score_norm

ivreg end_aser_math_norm (CCE_implement_rpt=any_CCE) any_LEP `baseline_test_prim' `child_control_prim' zstratum*, cluster(super_school_id)
store_ci CCE_implement_rpt
estimates store end_aser_math_norm

ivreg end_m_score_norm (CCE_implement_rpt=any_CCE) any_LEP `baseline_test_prim' `child_control_prim' zstratum*, cluster(super_school_id)
store_ci CCE_implement_rpt
estimates store end_m_score_norm

esttab * using ./csv/iv_test_prim.csv, se replace ///
	keep(CCE_implement_rpt any_LEP) ///
	stats(N r2 lower_ci_CCE_implement_rpt upper_ci_CCE_implement_rpt) ///
	nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)
	
format_csv using ./csv/iv_test_prim.csv, spacers(2)
estimates clear

*Upper Primary
use ./dta/upperprimary_cleaned.dta, clear

ivreg end_H_norm (CCE_implement_rpt=CCE) `baseline_test_up' `child_control_up' zstratum*, cluster(super_school_id)
store_ci CCE_implement_rpt
estimates store end_H_norm

eststo: ivreg end_M_norm (CCE_implement_rpt=CCE) `baseline_test_up' `child_control_up' zstratum*, cluster(super_school_id)
store_ci CCE_implement_rpt
estimates store end_M_norm

esttab * using ./csv/iv_test_upper.csv, se replace keep(CCE_implement_rpt)  ///
	stats(N r2 lower_ci_CCE_implement_rpt upper_ci_CCE_implement_rpt) ///
	nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)
	
format_csv using ./csv/iv_test_upper.csv
estimates clear

*Robustness: weighted by class size

use ./dta/primary_cleaned, clear

areg end_aser_read_norm any_CCE any_LEP [pw=pweight], absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store aser_read_1
		
areg end_aser_read_norm any_CCE any_LEP `baseline_test_prim' [pw=pweight], absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store aser_read_2

areg end_aser_read_norm any_CCE any_LEP `baseline_test_prim' `child_control_prim' [pw=pweight], absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store aser_read_3

areg end_h_score_norm any_CCE any_LEP [pw=pweight], absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store writ_h_1
	
areg end_h_score_norm any_CCE any_LEP `baseline_test_prim' [pw=pweight], absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store writ_h_2

areg end_h_score_norm any_CCE any_LEP `baseline_test_prim' `child_control_prim' [pw=pweight], absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store writ_h_3


areg end_aser_math_norm any_CCE any_LEP [pw=pweight], absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store aser_math_1

areg end_aser_math_norm any_CCE any_LEP `baseline_test_prim' [pw=pweight], absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store aser_math_2

areg end_aser_math_norm any_CCE any_LEP `baseline_test_prim' `child_control_prim' [pw=pweight], absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store aser_math_3

areg end_m_score_norm any_CCE any_LEP [pw=pweight], absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store writ_m_1 

areg end_m_score_norm any_CCE any_LEP `baseline_test_prim' [pw=pweight], absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store writ_m_2

areg end_m_score_norm any_CCE any_LEP `baseline_test_prim' `child_control_prim' [pw=pweight], absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store writ_m_3

esttab aser_read* writ_h* using ./csv/test_prim_weighted.csv, se replace ///
	keep(any_CCE any_LEP) ///
	stats(N r2 lower_ci_any_CCE upper_ci_any_CCE) ///
	nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)
	
esttab aser_math* writ_m* using ./csv/test_prim_weighted.csv, se append ///
	keep(any_CCE any_LEP) ///
	stats(N r2 lower_ci_any_CCE upper_ci_any_CCE) ///
	nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)
	
format_csv using ./csv/test_prim_weighted.csv, spacers(3)

estimates clear


****************************
* TEST SCORE HETEROGENEITY *
****************************
estimates clear 
use ./dta/primary_cleaned, clear

gen inter=.
gen CCE_inter=.
gen LEP_inter=.

foreach test in aser_read_norm h_score_norm aser_math_norm m_score_norm {
	replace inter=base_`test'
	replace CCE_inter=inter*any_CCE
	replace LEP_inter=inter*any_LEP
	eststo: areg end_`test' any_CCE any_LEP inter CCE_inter LEP_inter ///
		`baseline_test_prim' `child_control_prim' if base_`test'_m==0, absorb(stratum) vce(cluster super_school_id)
		}

esttab * using ./csv/prim_het_test.csv, se keep(any_CCE inter CCE_inter) ///
	stats(N r2) replace nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)
format_csv using ./csv/prim_het_test.csv, spacers(2)
estimates clear

*New/old schools
replace inter=new
replace CCE_inter=inter*any_CCE
replace LEP_inter=inter*any_LEP
foreach test in aser_read_norm h_score_norm aser_math_norm m_score_norm {
	eststo: areg end_`test' any_CCE any_LEP inter CCE_inter LEP_inter ///
		`baseline_test_prim' `child_control_prim' if base_`test'_m==0, absorb(stratum) vce(cluster super_school_id)
		}

esttab * using ./csv/prim_het_oldnew.csv, se keep(any_CCE inter CCE_inter) ///
	stats(N r2) replace nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)
format_csv using ./csv/prim_het_oldnew.csv, spacers(2)
estimates clear

*Absent at first post-test visit
replace inter=end_absent_any
replace CCE_inter=inter*any_CCE
replace LEP_inter=inter*any_LEP
foreach test in aser_read_norm h_score_norm aser_math_norm m_score_norm {
	eststo: areg end_`test' any_CCE any_LEP inter CCE_inter LEP_inter ///
		`baseline_test_prim' `child_control_prim' if base_`test'_m==0, absorb(stratum) vce(cluster super_school_id)
		}

esttab * using ./csv/prim_het_absent.csv, se keep(any_CCE inter CCE_inter) ///
	stats(N r2) replace nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)
format_csv using ./csv/prim_het_absent.csv, spacers(2)
estimates clear


*Student-teacher ratio (proxy for class size)
replace inter=str_lower
replace CCE_inter=inter*any_CCE
replace LEP_inter=inter*any_LEP
foreach test in aser_read_norm h_score_norm aser_math_norm m_score_norm {
	eststo: areg end_`test' any_CCE any_LEP inter CCE_inter LEP_inter ///
		`baseline_test_prim' `child_control_prim' if base_`test'_m==0, absorb(stratum) vce(cluster super_school_id)
		}

esttab * using ./csv/prim_het_size_var.csv, se keep(any_CCE inter CCE_inter) ///
	stats(N r2) replace nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)

estimates clear		
		
*Within-class variance

foreach test in aser_read_norm h_score_norm aser_math_norm m_score_norm {
	replace inter=var_base_`test'
	replace CCE_inter=inter*any_CCE
	replace LEP_inter=inter*any_LEP
	eststo: areg end_`test' any_CCE any_LEP inter CCE_inter LEP_inter ///
		`baseline_test_prim' `child_control_prim' if base_`test'_m==0, absorb(stratum) vce(cluster super_school_id)
		}

esttab * using ./csv/prim_het_size_var.csv, se keep(any_CCE inter CCE_inter) ///
	stats(N r2) append nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)		
		
format_csv using ./csv/prim_het_size_var.csv, spacers(2)
estimates clear

*Upper primary	
use ./dta/upperprimary_cleaned.dta, clear

gen inter=.
gen CCE_inter=.

foreach test in H_norm M_norm {
	replace inter=base_`test'
	replace CCE_inter=inter*any_CCE
	eststo: areg end_`test' CCE inter CCE_inter `baseline_test_up' `child_control_up' if base_`test'_m==0, absorb(stratum) vce(cluster super_school_id)
	}

esttab * using ./csv/up_het_test.csv, se replace keep(CCE inter CCE_inter) ///
	stats(N r2) nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)
	
format_csv using ./csv/up_het_test.csv 	

estimates clear

*Absent at post-test
replace inter=end_absent_any
replace CCE_inter=inter*any_CCE
foreach test in H_norm M_norm {
	eststo: areg end_`test' CCE inter CCE_inter `baseline_test_up' `child_control_up' if base_`test'_m==0, absorb(stratum) vce(cluster super_school_id)
	}
	
esttab * using ./csv/up_het_test_absent.csv, se replace keep(CCE inter CCE_inter) ///
	stats(N r2) nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)
	
format_csv using ./csv/up_het_test_absent.csv 	

estimates clear

*Class Size
replace inter=str_upper
replace CCE_inter=inter*any_CCE
foreach test in H_norm M_norm {
	eststo: areg end_`test' CCE inter CCE_inter `baseline_test_up' `child_control_up' if base_`test'_m==0, absorb(stratum) vce(cluster super_school_id)
	}
esttab * using ./csv/up_het_size_var.csv, se replace keep(CCE inter CCE_inter) ///
	stats(N r2) nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)
	
estimates clear

*Within-Class Variance
foreach test in H_norm M_norm {
	replace inter=var_base_`test'
	replace CCE_inter=inter*any_CCE
	eststo: areg end_`test' CCE inter CCE_inter `baseline_test_up' `child_control_up' if base_`test'_m==0, absorb(stratum) vce(cluster super_school_id)
	}
	
esttab * using ./csv/up_het_size_var.csv, se append keep(CCE inter CCE_inter) ///
	stats(N r2) nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)
	
format_csv using ./csv/up_het_size_var.csv 	


estimates clear

****************************************
* COMPLEMENTARITY BETWEEN TaRL and CCE *
****************************************

use ./dta/primary_cleaned, clear

areg end_aser_read_norm any_CCE any_LEP CCE_LEP `baseline_test_prim' `child_control_prim', absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store aser_read_3

areg end_h_score_norm any_CCE any_LEP CCE_LEP `baseline_test_prim' `child_control_prim' , absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store writ_h_3

areg end_aser_math_norm any_CCE any_LEP CCE_LEP `baseline_test_prim' `child_control_prim' , absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store aser_math_3

areg end_m_score_norm any_CCE any_LEP CCE_LEP `baseline_test_prim' `child_control_prim' , absorb(stratum) vce(cluster super_school_id)
store_ci any_CCE
estimates store writ_m_3

esttab * using ./csv/test_prim_comp.csv, se replace keep(any_CCE any_LEP CCE_LEP) ///
	stats(N r2) nonotes nonumbers star(* 0.10 ** 0.05 *** 0.05)

format_csv using ./csv/test_prim_comp.csv, spacers(2)

estimates clear

**************
* Attendance *
**************
use dta/process_cleaned, clear
collapse(mean) q1_9_hc_25 q1_9_reg_25 q1_9_hc_8 q1_9_reg_8, by(any_CCE any_LEP school_id super_school_id school_type stratum)
preserve

areg q1_9_hc_25 q1_9_reg_25 any_CCE any_LEP if school_type==1, cluster(super_school_id) absorb(stratum)
sum q1_9_hc_25 if any_CCE==0 & any_LEP==0 & e(sample)==1
estadd scalar depmean=r(mean)
estimates store prim_proc

use ./dta/primary_cleaned, clear
areg end_days_missed any_CCE any_LEP base_days_missed_m0 base_days_missed_m, cluster(super_school_id) absorb(stratum)
sum end_days_missed if any_CCE==0 & any_LEP==0 & e(sample)==1
estadd scalar depmean=r(mean)
estimates store prim_self

*Robustness (not reported): all controls
areg end_days_missed any_CCE any_LEP base_days_missed_m0 base_days_missed_m `baseline_test_prim' `child_control_prim', cluster(super_school_id) absorb(stratum)

restore
areg q1_9_hc_8 q1_9_reg_8 any_CCE if school_type==2, cluster(super_school_id) absorb(stratum)
sum q1_9_hc_8 if any_CCE==0 & e(sample)==1
estadd scalar depmean=r(mean)
estimates store up_proc

use ./dta/upperprimary_cleaned, clear

areg end_days_missed any_CCE base_days_missed_m0 base_days_missed_m, cluster(super_school_id) absorb(stratum)
sum end_days_missed if any_CCE==0 & e(sample)==1
estadd scalar depmean=r(mean)
estimates store up_self

*Robustness (not reported): all controls
areg end_days_missed any_CCE base_days_missed_m0 base_days_missed_m `baseline_test_up' `child_control_up', cluster(super_school_id) absorb(stratum)

esttab prim_proc prim_self using ./csv/attend_raw.csv, se replace keep(any_CCE any_LEP) ///
	stats(depmean N r2) nonumbers nonotes star(* 0.10 ** 0.05 *** 0.05)
esttab up_proc up_self using ./csv/attend_raw.csv, se append keep(any_CCE) ///
	stats(depmean N r2) nonumbers nonotes mlabels(none) star(* 0.10 ** 0.05 *** 0.05)

format_csv using ./csv/attend_raw.csv

*Not shown: regressions using whether students were absent during endline
use dta/primary_cleaned, clear

areg end_absences any_CCE any_LEP , cluster(super_school_id) absorb(stratum)
areg end_absent_any any_CCE any_LEP , cluster(super_school_id) absorb(stratum)

use dta/upperprimary_cleaned, clear

areg end_absences any_CCE, cluster(super_school_id) absorb(stratum)
areg end_absent_any any_CCE, cluster(super_school_id) absorb(stratum)

************************
* Evaluation Practices *
************************

use ./dta/process_cleaned, clear

local eval_prac q7_4_evalno_1 q7_4_evalno_2 q7_4_evalno_3 q7_4_evalno_4 q7_4_evalno_7 

replace any_LEP=0 if group==3|group==4

collapse (mean) `eval_prac', by(school_id school_type any_CCE any_LEP super_school_id group stratum)

genindex q7_4_evalno_1 q7_4_evalno_2 q7_4_evalno_3 q7_4_evalno_4 q7_4_evalno_7, ///
	prefix("eval_prac") label("KKL Index of Use of Evaluation Data")

local eval_prac `eval_prac' eval_prac_index
	
foreach var of varlist `eval_prac' {
	estpost tabstat `var', by(any_CCE) nototal
	mat m_`var'=e(mean)
	areg `var' any_CCE any_LEP, cluster(super_school_id) absorb(stratum)
	mat eval_all=nullmat(eval_all)\m_`var',_b[any_CCE]\.,.,_se[any_CCE]
	}

foreach var of varlist `eval_prac' {
	estpost tabstat `var' if school_type==1, by(group) nototal
	mat m_`var'=e(mean)
	areg `var' any_CCE if school_type==1, cluster(super_school_id) absorb(stratum)
	mat eval_prim=nullmat(eval_prim)\m_`var',_b[any_CCE]\.,.,_se[any_CCE]
	}

foreach var of varlist `eval_prac' {
	estpost tabstat `var' if school_type==2, by(group) nototal
	mat m_`var'=e(mean)
	areg `var' any_CCE if school_type==2, cluster(super_school_id) absorb(stratum)
	mat eval_up=nullmat(eval_up)\m_`var',_b[any_CCE]\.,.,_se[any_CCE]
	}

mat eval_prac=eval_all,eval_prim,eval_up

mat colnames eval_prac=all_nocce all_cce all_diff prim_nocce prim_cce prim_diff ///
	upper_nocce upper_cce upper_diff

clear
svmat eval_prac, names(col)

mat drop eval_prac eval_all eval_prim eval_up

gen outcome=""
local outcomes `eval_prac'
local i=1
foreach outcome in `outcomes' {
	replace outcome="`outcome'" in `i'
	local i=`i'+2
	}
order outcome

format_col all_nocce all_cce prim_nocce prim_cce upper_nocce upper_cce
format_col all_diff prim_diff upper_diff, delimiters("()") stars
	
export delimited using ./csv/evaluation_prac.csv, replace

format_csv using ./csv/evaluation_prac.csv, allquote spacers(3 6)

**************************
* Use of Evaluation Data *
**************************
use ./dta/process_cleaned, clear

local eval_use q7_14_datano_2 q7_14_datano_3 q7_14_datano_4 q7_14_datano_5 ///
	q7_14_datano_6 

replace any_LEP=0 if group==3|group==4

collapse (mean) `eval_use' q7_14_datano_1, by(school_id school_type any_CCE any_LEP super_school_id group stratum)

genindex q7_14_datano_2 q7_14_datano_3 q7_14_datano_4 q7_14_datano_5 q7_14_datano_6, ///
	prefix("eval_use") label("KKL Index of Use of Evaluation Data")

local eval_use `eval_use' eval_use_index q7_14_datano_1

foreach var of varlist `eval_use' {
	estpost tabstat `var', by(any_CCE) nototal
	mat m_`var'=e(mean)
	areg `var' any_CCE any_LEP, cluster(super_school_id) absorb(stratum)
	mat eval_all=nullmat(eval_all)\m_`var',_b[any_CCE]\.,.,_se[any_CCE]
	}

foreach var of varlist `eval_use' {
	estpost tabstat `var' if school_type==1, by(group) nototal
	mat m_`var'=e(mean)
	areg `var' any_CCE any_LEP if school_type==1, cluster(super_school_id) absorb(stratum)
	mat eval_prim=nullmat(eval_prim)\m_`var',_b[any_CCE]\.,.,_se[any_CCE]
	}

foreach var of varlist `eval_use' {
	estpost tabstat `var' if school_type==2, by(group) nototal
	mat m_`var'=e(mean)
	areg `var' any_CCE if school_type==2, cluster(super_school_id) absorb(stratum)
	mat eval_up=nullmat(eval_up)\m_`var',_b[any_CCE]\.,.,_se[any_CCE]
	}

mat eval_use=eval_all,eval_prim,eval_up	
	
mat colnames eval_use=all_nocce all_cce all_diff prim_nocce prim_cce prim_diff ///
	upper_nocce upper_cce upper_diff

clear
svmat eval_use, names(col)

mat drop eval_use eval_all eval_prim eval_up

gen outcome=""
local outcomes `eval_use'
local i=1
foreach outcome in `outcomes' {
	replace outcome="`outcome'" in `i'
	local i=`i'+2
	}
order outcome

format_col all_nocce all_cce prim_nocce prim_cce upper_nocce upper_cce
format_col all_diff prim_diff upper_diff, delimiters("()") stars
	
export delimited using ./csv/evaluation_use.csv, replace

format_csv using ./csv/evaluation_use.csv, allquote spacers(3 6)


***********************
* Classroom Practices *
***********************

use ./dta/process_cleaned, clear
replace any_LEP=0 if group==3|group==4

local class_obs q6_15_exmpls_observed q6_16_concpts_observed q6_17_repeat_observed q6_18_reteach_observed

collapse (mean) `class_obs', by(school_id school_type any_CCE any_LEP control super_school_id group stratum)

local class_obs `class_obs' teach_prac_index
	
genindex q6_15_exmpls_observed q6_16_concpts_observed q6_17_repeat_observed ///
	q6_18_reteach_observed, prefix("teach_prac") ///
	label("KKL Index of CCE-encouraged teaching practices")
	
foreach var of varlist `class_obs' {
	estpost tabstat `var', by(any_CCE) nototal
	mat m_`var'=e(mean)
	areg `var' any_CCE any_LEP, cluster(super_school_id) absorb(stratum)
	mat class_all=nullmat(class_all)\m_`var',_b[any_CCE]\.,.,_se[any_CCE]
	*Get p-values for FDR correction
	local pvalue=2*ttail(e(df_r), abs(_b[any_CCE]/_se[any_CCE]))
	if "`var'"!="teach_prac_index" mat pvalue_all=nullmat(pvalue_all) \ `pvalue'
	}

foreach var of varlist `class_obs' {
	estpost tabstat `var' if school_type==1, by(group) nototal
	mat m_`var'=e(mean)
	areg `var' any_CCE if school_type==1, cluster(super_school_id) absorb(stratum)
	mat class_prim=nullmat(class_prim)\m_`var',_b[any_CCE]\.,.,_se[any_CCE]
	*Get p-values for FDR correction
	local pvalue=2*ttail(e(df_r), abs(_b[any_CCE]/_se[any_CCE]))
	if "`var'"!="teach_prac_index" mat pvalue_prim=nullmat(pvalue_prim) \ `pvalue'
	}

foreach var of varlist `class_obs' {
	estpost tabstat `var' if school_type==2, by(group) nototal
	mat m_`var'=e(mean)
	areg `var' any_CCE if school_type==2, cluster(super_school_id) absorb(stratum)
	test any_CCE
	mat class_up=nullmat(class_up)\m_`var',_b[any_CCE]\.,.,_se[any_CCE]
	*Get p-values for FDR correction
	local pvalue=2*ttail(e(df_r), abs(_b[any_CCE]/_se[any_CCE]))
	if "`var'"!="teach_prac_index" mat pvalue_upper=nullmat(pvalue_upper) \ `pvalue'
	}

mat class_obs=class_all,class_prim,class_up
mat colnames class_obs=all_nocce all_cce all_diff prim_nocce prim_cce prim_diff ///
		upper_nocce upper_cce upper_diff
		
clear
svmat class_obs, names(col)

gen outcome=""
local outcomes `class_obs'
local i=1
foreach outcome in `outcomes' {
	replace outcome="`outcome'" in `i'
	local i=`i'+2
	}
order outcome

format_col all_nocce all_cce prim_nocce prim_cce upper_nocce upper_cce
format_col all_diff prim_diff upper_diff, delimiters(()) stars

export delimited using ./csv/teaching_practices_raw.csv, replace

format_csv using ./csv/teaching_practices_raw.csv, allquote spacers(3 6)

keep outcome all_diff prim_diff upper_diff
gen sno=_n/2+.5

tempfile diffs
save `diffs'

*FDR correction
clear
mat pvalues=pvalue_all,pvalue_prim,pvalue_upper
svmat pvalues
rename pvalues1 pvalue_all
rename pvalues2 pvalue_prim
rename pvalues3 pvalue_upper
qqvalue pvalue_all, method(simes) qvalue(qvalue_all)
qqvalue pvalue_prim, method(simes) qvalue(qvalue_prim)
qqvalue pvalue_upper, method(simes) qvalue(qvalue_upper)
gen sno=_n

merge 1:1 sno using `diffs'

sort sno
order sno outcome all_diff pvalue_all qvalue_all prim_diff pvalue_prim qvalue_prim ///
	upper_diff pvalue_upper qvalue_upper

*Drop index
drop if sno>=5

drop sno _merge

format pvalue_* qvalue_* %05.3f

export delimited using ./csv/teaching_practices_qvalues.csv, datafmt replace

format_csv using ./csv/teaching_practices_qvalues.csv, spacers(3 6) allquote

***********************
* Miscellaneous Stats *
***********************

*Introduction
*Overall percentage of teachers using both evaluation sheets and report cards
use dta/process_cleaned, clear
sum CCE_implement_rpt if any_CCE==1
collapse(mean) CCE_implement_rpt, by(school_id any_CCE)
sum CCE_implement_rpt if any_CCE==1

*Number of school campuses
use dta/primary_cleaned, clear
append using dta/upperprimary_cleaned
egen school_campus_counter=group(super_school_id)
sum school_campus_counter

*Number of students in sample
use dta/primary_cleaned, clear
count
use dta/upperprimary_cleaned, clear
count

*Section 4.2

*Additional test score summary statistics 
use dta/primary_cleaned, clear
count if base_h_score_weighted<6.25 & control==1
local lthalf=r(N)
count if base_h_score_weighted<. & control==1
di `lthalf'/r(N)
count if base_m_score_weighted<6.25 & control==1
local lthalf=r(N)
count if base_m_score_weighted<. & control==1
di `lthalf'/r(N)

use dta/upperprimary_cleaned, clear
count if base_H_score<30 & control==1
local lthalf=r(N)
count if base_H_score<. & control==1
di `lthalf'/r(N)
count if base_M_score<30 & control==1
local lthalf=r(N)
count if base_M_score<. & control==1
di `lthalf'/r(N)

*Magnitude of differences between CCE and Control for ASER variables
use dta/primary_cleaned, clear
areg base_aser_read_norm any_CCE any_LEP, cluster(super_school_id) absorb(stratum)
areg base_aser_math_norm any_CCE any_LEP, cluster(super_school_id) absorb(stratum)

*Section 6.1

*Implementation
use dta/primary_cleaned, clear
collapse(mean) CCE_implement_rpt, by(school_id any_CCE)
sum CCE_implement_rpt if any_CCE==1

use dta/upperprimary_cleaned, clear
collapse(mean) CCE_implement_rpt, by(school_id any_CCE)
sum CCE_implement_rpt if any_CCE==1

*ABRCs as resources
use dta/process_cleaned, clear
collapse(mean) abrc_last30 q5_9_abrc_cce_uc q5_10_10, by(school_id any_CCE)

sum abrc_last30 q5_9_abrc_cce_uc q5_10_10 if any_CCE==1

*How do teachers view CCE-related paperwork
*Possible answers:
*1. Does not affect teaching
*2. Adversely affects teaching
*3. positively affects teaching
*4. positively and negatively affects teaching

use dta/process_cleaned, clear
tab q8_18_cce if q8_18_cce>=0 & q8_18_cce<98

*Do teachers *think* that evaluation data is useful for identifying low-performing students
sum q7_12_useno_3 if any_CCE==1

*Do teachers in RE schools complete TaRL Assessment recording charts
sum q4_8_recrd_chart_compl_uc if any_LEP==1
sum q4_8_recrd_chart_compl_uc if any_LEP==1 & any_CCE==0
sum q4_8_recrd_chart_compl_uc if any_LEP==1 & any_CCE==1

*Implementation problems reported by headmasters
*Possible answers
*1. CCE guidelines not clear
*2. Teachers not trained
*3. Assessment sheet / materials not provided
*4. Teachers unable to implement CCE
*5. no ongoing academic support
*6. No issues
*7. Too time consuming
*8. Too burdensome
*97. Don't know
*98. Other

use dta/headmaster_cleaned, clear
sum q35_prob_1-q35_prob_98

*Top coding (Section 4.2)

use dta/primary_cleaned, clear
tab end_aser_read_weighted
tab end_aser_math_weighted

tab end_aser_read_weighted if base_standard==4
tab1 end_h_score_weighted end_m_score_weighted

use dta/upperprimary_cleaned, clear
sum end_H_score end_M_score

*Test score differences by standard (Section 5.2)
use dta/primary_cleaned, clear

reg end_aser_read_norm base_standard, cluster(super_school_id)
reg end_aser_math_norm base_standard, cluster(super_school_id)

reg end_h_score_norm base_standard, cluster(super_school_id)
reg end_m_score_norm base_standard, cluster(super_school_id)

*Number of visits by school (section 4.1)
use dta/primary_cleaned, clear
tab end_visit_num
sum visit_daysafter if visit_daysafter>0
collapse(mean) end_num_visit_school, by(school_id)
sum end_num_visit_school

use dta/upperprimary_cleaned, clear
tab end_visit_num
sum visit_daysafter if visit_daysafter>0
collapse(mean) end_num_visit_school, by(school_id)
sum end_num_visit_school

*Teacher Training
*Analyze end-of-training questions
*Count skips as wrong

use dta/EOT_CCE_april, clear

gen q6_correct=q6_cce==4 
gen q7_correct=q7_educa==2 
gen q8_correct=q8==2
gen q9_correct=q9==1
gen q10_correct=q10==2 
gen q11_correct=q11==3

egen cce_score=rowmean(q*_correct)

sum cce_score q6_correct

*Non-other attrition reasons
use dta/primary_cleaned, clear
tab admin_aser_hindi_reason

log close
